package com.mico.example.springboot.config.web;

import com.mico.example.springboot.config.domain.ConfigFromOtherFile;
import com.mico.example.springboot.config.domain.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * Created by micocube
 * ProjectName: springboot-example
 * PackageName: com.mico.example.springboot.config.web
 * User: micocube
 * Email: ldscube@gmail.com
 * CreateTime: 2019/2/25上午10:45
 * ModifyTime: 2019/2/25上午10:45
 * Version: 0.1
 * Description:
 **/
@RestController
public class PersonController {
    @Autowired
    Person person;
    @Autowired
    ConfigFromOtherFile configFromOtherFile;

    @GetMapping("/Person/Application")
    public Person getPerson() {
        return person;
    }

    @GetMapping("/Person/Config")
    public ConfigFromOtherFile getConfig() {
        return configFromOtherFile;
    }

    @PutMapping("/Person")
    public String create(@Valid Person person, BindingResult bindingResult) {
        if(bindingResult.hasErrors()){
            return "error user" + bindingResult.getAllErrors();
        }
        return "create Success";
    }
}
